package com.example.administrator.zkdemo.fragment;

import android.os.Bundle;
import android.support.annotation.IdRes;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import butterknife.ButterKnife;
import butterknife.Unbinder;

public abstract class ZKBaseFragment extends Fragment {
    private FragmentManager mFragmentManager;
    private Unbinder mUnbinder;

    public Bundle finishFragment(Bundle paramBundle) {
        this.mFragmentManager.popBackStack();
        return paramBundle;
    }

    public void finishFragment() {
        this.mFragmentManager.popBackStack();
    }

    public void initFragment(@IdRes int paramInt, Fragment paramFragment) {
        FragmentTransaction localFragmentTransaction = this.mFragmentManager.beginTransaction();
        localFragmentTransaction.replace(paramInt, paramFragment);
        localFragmentTransaction.addToBackStack(paramFragment.getClass().getName());
        localFragmentTransaction.commit();
    }

    protected abstract int initLayout();

    public void onCreate(@Nullable Bundle paramBundle) {
        super.onCreate(paramBundle);
        this.mFragmentManager = getActivity().getSupportFragmentManager();
    }

    public View onCreateView(LayoutInflater paramLayoutInflater, ViewGroup paramViewGroup, Bundle paramBundle) {
        View view = paramLayoutInflater.inflate(initLayout(), paramViewGroup, false);
        this.mUnbinder = ButterKnife.bind(this, view);
        return view;
    }

    public void onDestroyView() {
        super.onDestroyView();
        this.mUnbinder.unbind();
    }

    public void pushFragment(@IdRes int paramInt, Fragment paramFragment) {
        FragmentTransaction localFragmentTransaction = this.mFragmentManager.beginTransaction();
        localFragmentTransaction.setCustomAnimations(2130837504, 2130837505, 2130837506, 2130837507);
        localFragmentTransaction.replace(paramInt, paramFragment);
        localFragmentTransaction.addToBackStack(paramFragment.getClass().getName());
        localFragmentTransaction.commit();
    }

    public void pushFragment(@IdRes int paramInt, Fragment paramFragment, Bundle paramBundle) {
        FragmentTransaction localFragmentTransaction = this.mFragmentManager.beginTransaction();
        paramFragment.setArguments(paramBundle);
        localFragmentTransaction.replace(paramInt, paramFragment);
        localFragmentTransaction.addToBackStack(paramFragment.getClass().getName());
        localFragmentTransaction.commit();
    }
}
